﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using UnityEngine;

// 放入场景内的植物
public class PlantInScene : CreatureInScene
{
    protected new PlantTableData _tableData;

    protected Grid _curGird;

    protected TimeLine _skillLine = new TimeLine();

    public void Init(CreatureTableData tableData)
    {
        base.InitData(tableData, new CreatureDynamicData());

        _tableData = base._tableData as PlantTableData;
    }

    // 种进格子里(植物主动种植，格子处于被动)
    public void GrowInGrid(Grid grid)
    {
        onGrow(grid);
    }

    public void RemoveFormGrid()
    {
        if (_curGird == null) { return; }

        onKilled();

        _curGird.SetPlant(null);

        ResMgr.instance.ReleaseObject(_modelRoot.gameObject);
    }

    public override bool CanBeAttackBy(CreatureInScene attacker)
    {
        if (!base.CanBeAttackBy(attacker)) { return false; }

        // 僵尸只能被植物攻击
        var zombie = attacker as ZombieInScene;
        if (zombie == null) { return false; }

        return true;
    }

    // 被种下时
    protected virtual void onGrow(Grid grid)
    {
        _curGird = grid;
        _curGird.SetPlant(this);

        var obj = ResMgr.instance.InstanceGameObject(_tableData.Path);
        _modelRoot = obj.transform;
        _modelRoot.position = _curGird.CenterPos;

        initModel(_modelRoot);

    }

    // 被杀死(铲除或被吃掉)
    protected virtual void onKilled()
    {

    }
}
